package cn.jsj.invite.aop.aspect;


import cn.jsj.invite.aop.PageSize;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author 卢斌
 */
public class PageSizeHandler implements ConstraintValidator<PageSize, Integer> {

    /**
     * 页码容量最大值
     */
    private int max;

    /**
     * 页码容量最小值
     */
    private int min;

    @Override
    public void initialize(PageSize constraintAnnotation) {
        this.max = constraintAnnotation.max();
        this.min = constraintAnnotation.min();
        if (this.min < 0) {
            this.min = 0;
        }
        if (this.max < this.min) {
            this.max = this.min;
        }
    }

    @Override
    public boolean isValid(Integer aLong, ConstraintValidatorContext constraintValidatorContext) {
        System.out.println("校验");
        if (aLong == null) {
            return false;
        }
        return aLong >= this.min && aLong <= this.max;
    }
}
